package Controller;

import Validate.Myvalidate;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;

@Path(value = "/login",viewPath = "/login")
public class LoginController extends Controller {
    public void index(){
        render("login.html");
    }

    @Before(Myvalidate.class)
    public void loginaction(){
        String username = get("username");
        String pwd = get("password");
        List<Record> records = Db.find("select * from admin where username = ? and pwd = ?", username, pwd);
        if (records.size() == 0){
            set("errmsg","登录失败");
            forwardAction("/msg/errindex");
        }else{
            setSessionAttr("isLogin","1");
            redirect("/manger");
        }
    }
}
